package top.myliangsl.newsapplets.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import top.myliangsl.newsapplets.domain.po.TNewsChannel;
import top.myliangsl.newsapplets.mapper.TNewsChannelMapper;

import java.util.List;

/**
 * 新闻频道列表
 *
 * @author xiaoliang
 */
@Service
@Slf4j
public class TNewsChannelService extends ServiceImpl<TNewsChannelMapper, TNewsChannel> {

    public void insertNewsChannel(String channelName) {
        QueryWrapper<TNewsChannel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("channel_name", channelName);
        List<TNewsChannel> newsChannelList = baseMapper.selectList(queryWrapper);
        if (CollectionUtils.isEmpty(newsChannelList)) {
            baseMapper.insert(TNewsChannel.builder().channelName(channelName).created(System.currentTimeMillis()).build());
        }
    }

    public List<TNewsChannel> findAllNewsChannel() {
        return this.list();
    }
}
